package DateUtil;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

/**
 * Created by areehy on 2016/8/13.
 */
public class DeviceDb extends SQLiteOpenHelper {
    public static final String CREATE_MESSAGE = "create table device("
            + "DI_ID integer primary key , "
            + "DI_NAME text,"
            + "DS_ID text,"     //状态id
            + "DS_VALID integer,"//是否有效
            + "DS_COLOR integer,"//电源灯颜色
            + "DS_TEM real,"//设备温度
            + "DS_CPU real,"//设备cpu占有率
            + "DS_RAM real,"//设备内存占有率
            + "DS_STATE integer)";//设备状态
    private Context mContext;

    public DeviceDb(Context context, String name, SQLiteDatabase.CursorFactory factory, int version)
    {
        super(context,name,factory,version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_MESSAGE);


    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Toast.makeText(mContext, "更新数据库", Toast.LENGTH_SHORT).show();
    }

    public void replacevalue(SQLiteDatabase db,  int DI_ID, String DI_NAME, String DS_ID, int DS_VALID,int DS_COLOR,double DS_TEM,
    double DS_CPU,double DS_RAM,int DS_STATE){
        ContentValues cv = new ContentValues();
        cv.put("DI_ID",DI_ID);
        cv.put("DI_NAME",DI_NAME);
        cv.put("DS_ID",DS_ID);
        cv.put("DS_VALID",DS_VALID);
        cv.put("DS_COLOR",DS_COLOR);
        cv.put("DS_TEM",DS_TEM);
        cv.put("DS_CPU",DS_CPU);
        cv.put("DS_RAM ",DS_RAM );
        cv.put("DS_STATE",DS_STATE);
        db.replace("device", null, cv);
    }
    public void addvalue(SQLiteDatabase db,  int DI_ID, String DI_NAME,String DS_ID,int DS_STATE){
        ContentValues cv = new ContentValues();
        cv.put("DI_ID",DI_ID);
        cv.put("DI_NAME",DI_NAME);
        cv.put("DS_ID",DS_ID);
        cv.put("DS_STATE",DS_STATE);
        db.replace("device", null, cv);
    }
}
